package com.cgs.query.service.jpa

import com.cgs.query.domain.ProjectDefineVo
import com.cgs.query.domain.QueryProject
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query

interface QueryProjectRepository : JpaRepository<QueryProject, String> {

    fun findBySourceId(sourceId: String): Set<QueryProject>?

    @Query("select new QueryProject(qp.name,qp.lockType) from QueryProject qp, Project2Define pd " +
            "where qp.name = pd.projectName and pd.defineId = ?1")
    fun findByDefineId(defineId: String): Set<QueryProject>?

    @Query("select new QueryProject(qp.name,qp.lockType) from QueryProject qp where qp.lockType = ?1")
    fun findByLockType(lockType: String): Set<QueryProject>?

    @Query("select new QueryProject(qp.name,qp.lockType) from QueryProject qp, Project2Define pd " +
            "where qp.name = pd.projectName and pd.defineId = ?1 and pd.version = ?2")
    fun findByDefineIdAndVersion(defineId: String, version: String): Set<QueryProject>?

    @Query("select new com.cgs.query.domain.ProjectDefineVo(pd,qd.name,qd.remark) from QueryDefine qd, Project2Define pd " +
            "where pd.projectName =?1 and pd.defineId = qd.id")
    fun findProjectDefineVoByProjectName(projectName: String): List<ProjectDefineVo>
}